package noppes.vc;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer;

public class VCRecipes$RecipeContainer {
   private LinkedHashMap<ItemStack, List<ItemStack>> items;
   public int width;
   public int height;
   public boolean isFurnace;
   // $FF: synthetic field
   final VCRecipes this$0;

   public VCRecipes$RecipeContainer(VCRecipes this$0) {
      this.this$0 = this$0;
      this.items = new LinkedHashMap();
      this.width = 1;
      this.height = 1;
      this.isFurnace = false;
      VCRecipes.List.add(this);
   }

   public void add(ItemStack output, Object[] params) {
      ShapedPrimer primer = CraftingHelper.parseShaped(params);
      IRecipe r = (IRecipe)(new ShapedRecipes("variedcommodities", primer.width, primer.height, primer.input, output)).setRegistryName(output.getItem().getRegistryName() + "_" + output.getItemDamage());
      if (r.getRecipeOutput() != null && !r.getRecipeOutput().isEmpty()) {
         List<ItemStack> input = new ArrayList();
         if (r instanceof ShapedRecipes) {
            ShapedRecipes recipe = (ShapedRecipes)r;
            this.width = recipe.recipeWidth;
            this.height = recipe.recipeHeight;

            for(Ingredient in : recipe.recipeItems) {
               if (in == Ingredient.EMPTY) {
                  input.add(ItemStack.EMPTY);
               } else {
                  Collections.addAll(input, in.getMatchingStacks());
               }
            }
         }

         this.items.put(r.getRecipeOutput(), input);
         VCRecipes.access$000().register(r);
      }
   }

   public void furnace(ItemStack input, ItemStack output) {
      this.isFurnace = true;
      this.add(input, output);
   }

   public void add(ItemStack input, ItemStack output) {
      List<ItemStack> l = new ArrayList();
      l.add(input);
      this.items.put(output, l);
   }

   public ItemStack output() {
      int i = 0;
      if (this.items.size() > 1) {
         i = (int)(System.currentTimeMillis() / 2000L % (long)this.items.size());
      }

      for(Entry<ItemStack, List<ItemStack>> entry : this.items.entrySet()) {
         if (i == 0) {
            return (ItemStack)entry.getKey();
         }

         --i;
      }

      return null;
   }

   public List<ItemStack> input() {
      int i = 0;
      if (this.items.size() > 1) {
         i = (int)(System.currentTimeMillis() / 2000L % (long)this.items.size());
      }

      for(Entry<ItemStack, List<ItemStack>> entry : this.items.entrySet()) {
         if (i == 0) {
            return (List)entry.getValue();
         }

         --i;
      }

      return null;
   }

   public boolean isFurnace() {
      return this.isFurnace;
   }
}
